package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.CodeRuleBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.CodeRuleMapper;
import com.koron.css2.serviceManage.queryBean.CodeRuleQueryBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 编码规则查询详情
 * @author 周新宇
 *
 */

public class CodeRuleQuery implements ServerInterface {

	private static Logger logger = LogManager.getLogger(CodeRuleQuery.class);
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

	MessageBean<CodeRuleBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", CodeRuleBean.class);
		
		try {
			CodeRuleBean beanForReturn = new CodeRuleBean();
			
			CodeRuleMapper mapper = factory.getMapper(CodeRuleMapper.class);
			CodeRuleQueryBean bean = null;
			bean = JsonUtils.objectToPojo(req.getData(), CodeRuleQueryBean.class);
			beanForReturn = mapper.findCodeRuleById(bean.getId());
			
			info.setCode(Constant.MESSAGE_INT_SUCCESS);
			info.setDescription("success");
			info.setData(beanForReturn);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_DBFAIL);
			info.setDescription("数据库异常");
			logger.error("数据库异常",e);
			factory.close(false);
		}
		return info;
	}

}
